<template>
    <div class="app-container">
        <!-- rules表单验证规则 -->
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" size="medium">
            <!-- <el-form-item label="车间" prop="typeworkCenter">
                <el-select v-model="form.typeworkCenter" style="width:300px">
                    <el-option :value="item" :label="item" v-for="(item,index) in this.workCenterList" :key="index"/>
                </el-select>
            </el-form-item> -->
            <el-form-item label="工单单别" prop="orderType">
                <el-input v-model="form.orderType" style="width:300px" />
            </el-form-item>
            <el-form-item label="工单单号" prop="workOrderNo">
                <el-input v-model="form.workOrderNo" style="width:300px"/>
            </el-form-item>
            <el-form-item label="入库数量" prop="MesCompletionQuantity">
                <el-input v-model.number="form.MesCompletionQuantity" style="width:300px"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('form')">添加</el-button>
                <el-button type="primary" @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { moctfadd,ptWorkOrderInWarehouse } from '@/api/productionPlan.js'
export default {
    name: 'cncWarehouse',
    data() {
        return {
            // workCenterList: ['非喷涂车间','喷涂车间'],
            form: {
                // typeworkCenter: '非喷涂车间',
                orderType: '',                          //工单单别
                workOrderNo: '',                        //工单单号
                MesCompletionQuantity: '',              //入库数量
            },
            rules: {
                // typeworkCenter: [
                //     { required: true, message: '车间不能为空！', trigger: 'blur' }
                // ],
                orderType: [
                    { required: true, message: '工单单别不能为空！', trigger: 'blur' }
                ],
                MesCompletionQuantity: [
                    { required: true, message: '入库数量不能为空！', trigger: 'blur' },
                    { type: 'number', message: '入库数量必须为数字值'}
                ],
                workOrderNo: [
                    { required: true, message: '工单单号不能为空！', trigger: 'blur' }
                ]
            },
        }
    },
    methods: {
        // 提交表单之前先进行验证
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.onSubmit()
            } else {
                return false
                }
            })
        },
        async onSubmit() {
            let query = Object.assign({},this.form)
            // if(this.form.typeworkCenter == '喷涂车间'){ query.isSpray = true }
            delete query.typeworkCenter
            // const data = this.form.typeworkCenter == '喷涂车间'?await ptWorkOrderInWarehouse(query):await moctfadd(query)
            const data = await moctfadd(query)
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(data.msg)
            this.$message.success(data.msg)
            this.resetForm('form')
        },
        // 对整个表单输入进去清空
        resetForm(formItem) {
          this.$refs[formItem].resetFields()
        }
    }
}
</script>

<style>

</style>
